package mystatic.src.LT.IChoice;

import mystatic.src.LT.Book.Book;
import mystatic.src.LT.Book.BookList;

import java.util.Scanner;

public class Borrow implements IChoice {
    @Override
    public void work(BookList bookList) {
        System.out.println("您正在访问借阅图书界面");
        System.out.println("请输入您需要借阅的图书的名字");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        int i;
        for(i=0;i< bookList.getCnt();i++){
            Book books=bookList.getBook(i);
            if(books.getTitle().equals(name)){
                if(books.isBorrowed()==false){
                    books.setBorrowed(true);
                    System.out.println("借阅成功 请在归还期内归还 谢谢");
                    return;
                }
                else{
                    System.out.println("抱歉 该书已被借阅 借阅失败");
                }

            }
        }
        if(i==bookList.getCnt()-1){
            System.out.println("未找到您需要借阅的书名");
        }
    }
}
